package com.sasac.test.service.impl;

import com.sasac.test.dao.StudentDao;
import com.sasac.test.domain.Student;
import com.sasac.test.projection.StudentProjection;
import com.sasac.test.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements IStudentService {


    @Autowired
    StudentDao studentDao;

    @Override
    public Student findById(Long id) {
        return studentDao.findById(id).get();
    }

    @Override
    public StudentProjection findStudentInfo(Long id) {
        return studentDao.findStudentInfo(id);
    }

    @Override
    public Page<StudentProjection> findStudentInfo1(Long id) {
        Pageable pageable = PageRequest.of(0,2);
        Page<StudentProjection> page = studentDao.findStudentInfo1(id,pageable);
        return page;
    }

    @Override
    public List<StudentProjection> findStudentInfo2(Long id) {
        List<StudentProjection> page = studentDao.findStudentInfo2(id);
        return page;
    }

//    @Override
//    public List<Student> findAll() {
//        return userDao.findAll();
//    }
}
